package my.concurrent;


import java.util.HashMap;
import java.util.Map;

public class UnsafeCount {

    private int value;

    private Map<Integer, Integer> map = new HashMap<>();

    public int increment() {
        return value++;
    }

    public static void main(String[] args) {

        UnsafeCount unsafeCount = new UnsafeCount();

        Runnable runnable = () -> {
            final int increment = unsafeCount.increment();
//            unsafeCount.map.compute(increment, (k, v) -> {
//                if ()
//            })
//            synchronized (unsafeCount) {
//                map.compute(increment, (k, v) -> {
//
//                })
//            }
            System.out.println(increment);
        };

        Runnable runnable2 = () -> {
            final int increment = unsafeCount.increment();
            System.out.println(increment);
        };

        for (int i = 0; i < 10; i++) {
            new Thread(runnable).start();
            new Thread(runnable2).start();
        }

    }


    private void t1() {

    }




}
